home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / dev / c / ExtrasLib.lha / ExtrasLib / Source / PM.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-30  |  21.3 KB  |  691 lines

  1. #include <extras/math.h>
  2. #include "pm.h"
  3. //#include <extras/progressmeter.h>
  4. #include <clib/extras_protos.h>
  5. #include <exec/memory.h>
  6. #include <graphics/rastport.h>
  7. #include <graphics/rpattr.h>
  8. #include <libraries/gadtools.h>
  9. #include <utility/tagitem.h>
  10.  
  11. #include <proto/diskfont.h>
  12. #include <proto/exec.h>
  13. #include <proto/gadtools.h>
  14. #include <proto/graphics.h>
  15. #include <proto/intuition.h>
  16. #include <proto/utility.h>
  17.  
  18.  
  19. #include <math.h>
  20. #include <string.h>
  21. #include <stdio.h>
  22.  
  23. #define CANCEL_ID 0
  24.  
  25. /* privete protos */
  26. void RenderBar(ProgressMeter PM);
  27. void MyText(struct RastPort *RP, STRPTR Str, UBYTE Pen, WORD X, WORD Y);
  28. void RefreshPM(ProgressMeter PM);
  29.  
  30. STRPTR def_low   =(UBYTE *)"0%",
  31.        def_high  =(UBYTE *)"100%",
  32.        def_cancel=(UBYTE *)"Cancel",
  33.        def_meter =(UBYTE *)"%ld%%";
  34.  
  35. struct TextAttr Topaz8=
  36. {
  37.   "topaz.font", 8,0,0
  38. };
  39.  
  40. /****** extras.lib/AllocProgressMeterA ******************************************
  41. *
  42. *   NAME
  43. *       AllocProgressMeterA -- Allocate and initialize a progressmeter.
  44. *       AllocProgressMeter -- varargs stub for AllocProgressMeterA().
  45. *
  46. *   SYNOPSIS
  47. *       meter = AllocProgressMeterA(TagList)
  48. *
  49. *       ProgressMeter AllocProgressMeterA( struct TagItem *);
  50. *
  51. *       meter = AllocProgressMeterA(Tag, ... )
  52. *
  53. *       ProgressMeter AllocProgressMeterA( Tag, ...);
  54. *
  55. *   FUNCTION
  56. *       This function allocates and initializes a ProgressMeter.
  57. *
  58. *   INPUTS
  59. *       TagList - 
  60. *         One of the following two are required.
  61. *         PM_Screen - The screen to place the meter on.
  62. *                     (struct Screen *)
  63. *         PM_ParentWindow - The parent window of the meter.
  64. *                           (struct Window *)
  65. *                           
  66. *         PM_MsgPort    - Already existing msgport to send the meter's
  67. *                         window events through. (Not implemented)
  68. *
  69. *         PM_TextAttr   - Font to use in the meter. defaults to the
  70. *                         screen font. (struct TextAttr *)
  71. *
  72. *         PM_LeftEdge   - Defaults to be centered on PM_ParentWindow
  73. *         PM_TopEdge    - or PMScreen.
  74. *         PM_MinWidth   - Set the minimum width of the meter's
  75. *                         window.
  76. *         PM_MinHeight  - Set the minimum height of the meter's
  77. *                         window (Not implemented).
  78. *
  79. *         PM_WinTitle   - Meter's Window title. (STRPTR) 
  80. *
  81. *         PM_LowText    - default "0%"   (STRPTR)  
  82. *         PM_HighText   - default "100%" (STRPTR)
  83. *
  84. *         PM_MeterFormat - A printf style format string used inside the meter.
  85. *                          default "%ld%%". (STRPTR) 
  86. *         PM_MeterType   - How PM_MeterFormat is used, 
  87. *                            PM_TYPE_PERCENTAGE - uses the percentage of
  88. *                              where PM_MeterValue is between PM_LowValue and
  89. *                              PM_HighValue for the argument of 
  90. *                              PM_MeterFormat.
  91. *                            PM_TYPE_NUMBER - Uses the meter's value for the 
  92. *                              argument of PM_MeterFormat.
  93. *                            PM_TYPE_STRING - Doens't process the meter's 
  94. *                              value simply displays the text from 
  95. *                              PM_MeterFormat
  96. *         PM_MeterLabel    - The label above the meter.  default NULL 
  97. *         PM_MinMeterWidth - The minimum meter bar width, the default minimum
  98. *                            is 80
  99. *
  100. *         PM_MeterPen      - default fillpen 
  101. *         PM_MeterBgPen    - default backgroundpen 
  102. *         PM_FormatPen     - default highlight text 
  103. *         PM_MeterLabelPen - default highlight text 
  104. *         PM_LowTextPen    - default text pen 
  105. *         PM_HighTextPen   - default text pen 
  106. *
  107. *         PM_MeterValue    - (IS) default   0 (LONG) 
  108. *         PM_LowValue      - (IS) default   0 (LONG)  
  109. *         PM_HighValue     - (IS) default 100 (LONG)
  110. *
  111. *         PM_Ticks         -  Ticks to draw under the meter box
  112. *                               defaults to 0 for none 
  113. *
  114. *         PM_CancelButton - Create a Cancel button? (BOOL)
  115. *         PM_CancelText   - Text for cancel button. default "Cancel". (STRPTR)
  116. *         PM_QueryCancel  - (S) The number of time the user
  117. *                           has pressed the cancel button since the last
  118. *                           PM_QueryCancel (ULONG *)  
  119. *
  120. *         the following three are not implemented 
  121. *         PM_CancelID - Creates an IDCMP_GADGETUP event when the Cancel button
  122. *                       is clicked. IntuiMessage->IAddress will be a pointer
  123. *                       to a gadget whose GadgetID is taken from this tag.
  124. *                       To be used in conjunctoin with the PM_MsgPort tag.
  125. *         PM_CancelSigNum  - Sets a signal when the Cancel button is clicked 
  126. *         PM_CancelSigTask - Task to signal (struct Task *)    
  127. *
  128. *   RESULT
  129. *       returns a pointer to a ProgressMeter. or NULL on failure.
  130. *
  131. *   EXAMPLE
  132. *
  133. *   NOTES
  134. *     requires diskfont, exec, gadtools, graphics, intuition & utility
  135. *     libraries to be open.
  136. *
  137. *   BUGS
  138. *       Currently uses SmartRefresh window.
  139. *
  140. *   SEE ALSO
  141. *       FreeProgressMeter(), UpdateProgressMeterA()
  142. *
  143. ******************************************************************************
  144. *
  145. */
  146.  
  147.  
  148. ProgressMeter AllocProgressMeter(Tag FirstTag, ... )
  149. {
  150.   return(AllocProgressMeterA((struct TagItem *)&FirstTag));
  151. }
  152.  
  153. ProgressMeter AllocProgressMeterA(struct TagItem *TagList)
  154. {
  155.   struct TagItem  *ti;
  156.   struct TextAttr *ta;
  157.   struct _ProgressMeter *pm;
  158.   WORD centerx,centery,leftedge,topedge,width,height,winlbor,winrbor,wintbor,winbbor,
  159.        rows=1, highlen,lowlen,hilowlen,meterlablen,cancellen,meterwidth;
  160.   struct NewGadget ng;
  161.   struct Gadget *gad;
  162.   STRPTR wintitle;
  163.   BOOL ok;
  164.  
  165.   if(pm=AllocVec(sizeof(struct _ProgressMeter),MEMF_CLEAR))
  166.   {
  167.     if(ti=FindTagItem(PM_ParentWindow,TagList))
  168.     {
  169.       pm->pm_ParentWindow=(struct Window *)ti->ti_Data;
  170.       pm->pm_Screen      =pm->pm_ParentWindow->WScreen;
  171.       
  172.       centerx=pm->pm_ParentWindow->LeftEdge + pm->pm_ParentWindow->Width  / 2;
  173.       centery=pm->pm_ParentWindow->TopEdge  + pm->pm_ParentWindow->Height / 2;
  174.     }
  175.     else
  176.       if(ti=FindTagItem(PM_Screen,TagList))
  177.       {
  178.         pm->pm_Screen=(struct Screen *)ti->ti_Data;
  179.       
  180.         centerx=pm->pm_Screen->Width/2;
  181.         centery=pm->pm_Screen->Height/2;
  182.       }
  183.     if(pm->pm_Screen)
  184.     {
  185.       if(pm->pm_VisualInfo=GetVisualInfo(pm->pm_Screen,0))
  186.       {
  187.         winlbor=pm->pm_Screen->WBorLeft;
  188.         winrbor=pm->pm_Screen->WBorRight;
  189.         wintbor=pm->pm_Screen->WBorTop+pm->pm_Screen->RastPort.TxHeight + 1;
  190.         winbbor=pm->pm_Screen->WBorBottom;
  191.   
  192.         ta=(struct TextAttr *)GetTagData(PM_TextAttr, (ULONG)pm->pm_Screen->Font, TagList);
  193.     
  194.         if(!(pm->pm_Font=OpenDiskFont(ta)))
  195.           pm->pm_Font=OpenDiskFont(&Topaz8);
  196.     
  197.         if(pm->pm_Font)
  198.         {
  199.           pm->pm_MeterLabel  =(STRPTR)GetTagData(PM_MeterLabel, 0,TagList);
  200.           pm->pm_MeterFormat =(STRPTR)GetTagData(PM_MeterFormat,(ULONG)def_meter  ,TagList);
  201.           pm->pm_MeterType   =GetTagData(PM_MeterType          ,PM_TYPE_PERCENTAGE,TagList);
  202.           pm->pm_LowText     =(STRPTR)GetTagData(PM_LowText    ,(ULONG)def_low    ,TagList);
  203.           pm->pm_HighText    =(STRPTR)GetTagData(PM_HighText   ,(ULONG)def_high   ,TagList);
  204.           if(GetTagData(PM_CancelButton,0,TagList))
  205.             pm->pm_CancelText  =(STRPTR)GetTagData(PM_CancelText ,(ULONG)def_cancel ,TagList);
  206.           meterwidth         =GetTagData(PM_MinMeterWidth ,80                ,TagList);
  207.     
  208.           highlen     =gui_StrFontLen(pm->pm_Font,pm->pm_HighText)+16;
  209.           lowlen      =gui_StrFontLen(pm->pm_Font,pm->pm_LowText)+16;
  210.           cancellen   =gui_StrFontLen(pm->pm_Font,pm->pm_CancelText)+16;
  211.           meterlablen =gui_StrFontLen(pm->pm_Font,pm->pm_MeterLabel)+16;
  212.                 
  213.           hilowlen=max(highlen,lowlen);
  214.     
  215.           width=GetTagData(PM_MinWidth, 0,TagList);
  216.           width=max(width,cancellen+16+winlbor+winrbor);     /* 16 = 8 pixels on either */
  217.           width=max(width,meterlablen+16+winlbor+winrbor); /* side of the gadget.     */
  218.           width=max(width,meterwidth+hilowlen+hilowlen+16+winlbor+winrbor);
  219.           width=min(pm->pm_Screen->Width,width);
  220.     
  221.           /* need to a PM_MinHeight support */
  222.           if(pm->pm_CancelText)
  223.             rows++;
  224.             
  225.           if(pm->pm_MeterLabel)
  226.             rows++;
  227.               
  228.           height  =wintbor+winbbor+(pm->pm_Font->tf_YSize+6)*rows+10;
  229.         
  230.           leftedge          =GetTagData(PM_LeftEdge   ,centerx-width/2 ,TagList);
  231.           topedge           =GetTagData(PM_TopEdge    ,centery-height/2,TagList);
  232.           pm->pm_MeterValue =GetTagData(PM_MeterValue ,0    ,TagList);
  233.           pm->pm_LowValue   =GetTagData(PM_LowValue   ,0    ,TagList);
  234.           pm->pm_HighValue  =GetTagData(PM_HighValue  ,100  ,TagList);
  235.           pm->pm_NumTicks   =GetTagData(PM_Ticks      ,0    ,TagList);
  236.           
  237.           if(pm->pm_DrawInfo=GetScreenDrawInfo(pm->pm_Screen))
  238.           {
  239.             pm->pm_MeterPen     = pm->pm_DrawInfo->dri_Pens[FILLPEN];
  240.             pm->pm_MeterBgPen   = pm->pm_DrawInfo->dri_Pens[BACKGROUNDPEN];
  241.             pm->pm_FormatPen    = pm->pm_DrawInfo->dri_Pens[FILLTEXTPEN];
  242.             pm->pm_MeterLabelPen= pm->pm_DrawInfo->dri_Pens[HIGHLIGHTTEXTPEN];
  243.             pm->pm_LowTextPen   =
  244.              pm->pm_HighTextPen = pm->pm_DrawInfo->dri_Pens[TEXTPEN];
  245.           
  246.             pm->pm_MeterPen   =GetTagData(PM_MeterPen      ,pm->pm_MeterPen     ,TagList);
  247.             pm->pm_MeterBgPen =GetTagData(PM_MeterBgPen    ,pm->pm_MeterBgPen   ,TagList);
  248.             pm->pm_FormatPen  =GetTagData(PM_FormatPen     ,pm->pm_FormatPen    ,TagList);
  249.             pm->pm_MeterLabelPen=GetTagData(PM_MeterLabelPen ,pm->pm_MeterLabelPen    ,TagList);
  250.             pm->pm_LowTextPen =GetTagData(PM_LowTextPen    ,pm->pm_LowTextPen   ,TagList);
  251.             pm->pm_HighTextPen=GetTagData(PM_HighTextPen   ,pm->pm_HighTextPen  ,TagList);
  252.             
  253.             wintitle=(STRPTR)GetTagData(PM_WinTitle,0,TagList);
  254.     
  255.             pm->pm_MeterCenter=(width-winlbor-winrbor)/2+winlbor;
  256.             pm->pm_LowCenter  =winlbor+4+hilowlen/2;
  257.             pm->pm_HighCenter =width-winrbor-4-hilowlen/2;
  258.             pm->pm_LabelY     =wintbor+4;
  259.             pm->pm_HiLowY     =pm->pm_LabelY;
  260.             if(pm->pm_MeterLabel)
  261.             {
  262.               pm->pm_HiLowY+=pm->pm_Font->tf_YSize+6;
  263.             }
  264.           
  265.             pm->pm_BarLeftEdge=winlbor+6+hilowlen;
  266.             pm->pm_BarWidth   =width-winrbor-hilowlen-6-pm->pm_BarLeftEdge;
  267.             pm->pm_BarTopEdge =pm->pm_HiLowY;
  268.             pm->pm_BarHeight  =pm->pm_Font->tf_YSize+6;
  269.             
  270.             pm->pm_HiLowY+=pm->pm_Font->tf_Baseline+2;
  271.             pm->pm_LabelY+=pm->pm_Font->tf_Baseline+2;
  272.             
  273.             ok=TRUE;
  274.             if(pm->pm_CancelText)
  275.             {
  276.               ok=FALSE;
  277.               if(gad=CreateContext(&pm->pm_GList))
  278.               {
  279.                 ng.ng_Flags=0;
  280.                 ng.ng_TextAttr=ta;
  281.                 ng.ng_VisualInfo=pm->pm_VisualInfo;
  282.                 ng.ng_GadgetText=0;
  283.                 ng.ng_UserData=0;
  284.                 ng.ng_Height=pm->pm_Font->tf_YSize+4;       
  285.                 
  286.                 ng.ng_TopEdge   =pm->pm_BarTopEdge+pm->pm_BarHeight+6;
  287.                 ng.ng_GadgetID  =CANCEL_ID;
  288.                 ng.ng_LeftEdge  =width/2-cancellen/2;
  289.                 ng.ng_Width     =cancellen;
  290.                 ng.ng_GadgetText=pm->pm_CancelText;
  291.                 if(pm->pm_GTGads[0]=gad=CreateGadget(BUTTON_KIND,gad,&ng,
  292.                                                   TAG_DONE))
  293.                   ok=TRUE;
  294.               }
  295.             }
  296.             if(ok)
  297.             {
  298.               if(pm->pm_MeterWindow=OpenWindowTags(0, WA_Width        ,width,
  299.                                                       WA_Height       ,height,
  300.                                                       WA_Left         ,leftedge,
  301.                                                       WA_Top          ,topedge,
  302.                                                       WA_Title        ,wintitle,
  303.                                                       WA_CustomScreen ,pm->pm_Screen,
  304.                                                       WA_DragBar      ,TRUE,
  305.                                                       WA_DepthGadget  ,TRUE,
  306.                                                       WA_SmartRefresh ,TRUE,
  307.                                                       WA_Gadgets      ,pm->pm_GList,
  308.                                                       WA_IDCMP        ,BUTTONIDCMP,
  309.                                                       TAG_DONE))
  310.               {
  311.                 SetFont(pm->pm_MeterWindow->RPort,pm->pm_Font);
  312.                 SetDrMd(pm->pm_MeterWindow->RPort,JAM1);
  313.  
  314.                 GT_RefreshWindow(pm->pm_MeterWindow,0);
  315.                 RefreshPM(pm);
  316.  
  317.                 return(pm);
  318.               } // endif OpenWindow
  319.             } // endif ok
  320.           } // endif GetScreenDrawInfo
  321.         } // endif pm_Font
  322.       } // endif GetVisualInfo
  323.     } // endif pm_Screen
  324.     FreeProgressMeter(pm);    
  325.   } // endif pm=AllocVec()
  326.   return(NULL);
  327. }      
  328.  
  329. /****** extras.lib/FreeProgressMeter ******************************************
  330. *
  331. *   NAME
  332. *       FreeProgressMeter -- Close a PregressMeter.
  333. *
  334. *   SYNOPSIS
  335. *       FreeProgressMeter(PM)
  336. *
  337. *       void FreeProgressMeter(ProgressMeter );
  338. *
  339. *   FUNCTION
  340. *       Close and deallocated a ProgressMeter.
  341. *
  342. *   INPUTS
  343. *       PM - pointer to an existing ProgressMeter or NULL.
  344. *
  345. *   RESULT
  346. *       none.
  347. *
  348. *   EXAMPLE
  349. *
  350. *   NOTES
  351. *     requires diskfont, exec, gadtools, graphics, intuition & utility
  352. *     libraries to be open.
  353. *
  354. *   BUGS
  355. *
  356. *   SEE ALSO
  357. *       AllocProgressMeterA(), UpdateProgressMeterA()
  358. *
  359. ******************************************************************************
  360. *
  361. */
  362.  
  363. void FreeProgressMeter(ProgressMeter ProgressMeter)
  364. {
  365.   struct _ProgressMeter *PM;
  366.   
  367.   PM=ProgressMeter;
  368.   
  369.   if(PM)
  370.   {
  371.  
  372.     if(PM->pm_MeterWindow)
  373.       CloseWindow(PM->pm_MeterWindow);
  374.     if(PM->pm_Screen)
  375.       FreeScreenDrawInfo(PM->pm_Screen,PM->pm_DrawInfo);
  376.     FreeGadgets(PM->pm_GList);
  377.     FreeVisualInfo(PM->pm_VisualInfo);
  378.     if(PM->pm_Font)
  379.       CloseFont(PM->pm_Font);
  380.     FreeVec(PM);
  381.   }
  382. }
  383.  
  384. /****** extras.lib/UpdateProgressMeterA ******************************************
  385. *
  386. *   NAME
  387. *       UpdateProgressMeterA -- Change ProgressMeter attributes.
  388. *       UpdateProgressMeter -- varargs stub.
  389. *
  390. *   SYNOPSIS
  391. *       numProcessed UpdateProgressMeterA(PM,TagList)
  392. *
  393. *       LONG UpdateProgressMeterA(ProgressMeter ,struct TagItem *);
  394. *
  395. *       numProcessed UpdateProgressMeter(PM,FirstTag)
  396. *
  397. *       LONG UpdateProgressMeter(ProgressMeter , Tag, ...);
  398. *
  399. *   FUNCTION
  400. *       Updates a ProgressMeter's attributes  and refreshes
  401. *       it as neccessary.
  402. *
  403. *   INPUTS
  404. *       PM - Pointer to an existing ProgressMeter or NULL.
  405. *       TagList - TagList of attributes to change or NULL.
  406. *           Only these four tags are processed.
  407. *             PM_QueryCancel
  408. *             PM_MeterValue
  409. *             PM_LowValue
  410. *             PM_HighValue
  411. *
  412. *   RESULT
  413. *       returns the number of tags processed.
  414. *
  415. *   EXAMPLE
  416. *
  417. *   NOTES
  418. *     requires diskfont, exec, gadtools, graphics, intuition & utility
  419. *     libraries to be open.
  420. *
  421. *   BUGS
  422. *
  423. *   SEE ALSO
  424. *     AllocProgressMeterA(), FreeProgressMeter() 
  425. *
  426. ******************************************************************************
  427. *
  428. */
  429.  
  430. LONG   UpdateProgressMeter(ProgressMeter PM, Tag FirstTag, ...)
  431. {
  432.   return(UpdateProgressMeterA(PM,(struct TagItem *)&FirstTag));
  433. }
  434.  
  435. LONG   UpdateProgressMeterA(ProgressMeter PMeter, struct TagItem *TagList)
  436. {
  437.   struct _ProgressMeter *PM;
  438.   LONG parsed=0;
  439.   ULONG data,count,*dp;
  440.   BOOL refreshbar=FALSE;
  441.   struct TagItem *tstate,*tag;
  442.   struct IntuiMessage *imsg;
  443.   
  444.   PM=PMeter;
  445.   
  446.   if(PM && TagList)
  447.   {
  448.     tstate=TagList;
  449.     while(tag=NextTagItem(&tstate))
  450.     {
  451.       parsed++;
  452.       data=tag->ti_Data;
  453.       dp=(ULONG *)data;
  454.       switch(tag->ti_Tag)
  455.       {
  456.         case PM_QueryCancel:
  457.           
  458.           if(dp)
  459.           {
  460.             count=0;
  461.             while(imsg=GT_GetIMsg(PM->pm_MeterWindow->UserPort))
  462.             {
  463.               if(imsg->Class==IDCMP_GADGETUP)
  464.                // if(((struct Gadget *)imsg->IAddress)->GadgetID==CANCEL_ID)
  465.                   count++;
  466.               GT_ReplyIMsg(imsg);
  467.             }
  468.             *dp=count;
  469.             
  470.           }
  471.           break;
  472.         case PM_MeterValue:
  473.           PM->pm_MeterValue=data;
  474.           refreshbar=TRUE;
  475.           break;
  476.         case PM_LowValue:
  477.           PM->pm_LowValue=data;
  478.           refreshbar=TRUE;
  479.           break;
  480.         case PM_HighValue:
  481.           PM->pm_HighValue=data;
  482.           refreshbar=TRUE;
  483.           break;
  484.         default:
  485.           parsed--;
  486.           break;
  487.       }
  488.     }
  489.   }
  490.   if(refreshbar)
  491.     RenderBar(PM);
  492.   return(parsed);
  493. }
  494.  
  495. void RenderBar(ProgressMeter PMeter)
  496. {
  497.   struct RastPort *rp;
  498.   LONG hi,lo;
  499.   float percent;
  500.   LONG ipercent;
  501.   WORD x,y,w,y1,pos;
  502.   UBYTE *fb;
  503.   UBYTE formatbuffer[26];
  504.   struct _ProgressMeter *PM;
  505.  
  506.   PM=PMeter;
  507.  
  508.  
  509.   
  510.   if(PM)
  511.   {
  512.     rp=PM->pm_MeterWindow->RPort;
  513.     x=PM->pm_BarLeftEdge+2;
  514.     w=PM->pm_BarWidth-4;
  515.  
  516.     y=PM->pm_BarTopEdge+1;
  517.     y1=PM->pm_BarHeight-3+y;
  518.     
  519.     lo=PM->pm_LowValue;
  520.     hi=PM->pm_HighValue-lo;
  521.     
  522.     if(hi)
  523.       percent=(float)(PM->pm_MeterValue-lo) / hi;
  524.     else
  525.       percent=1.0;
  526.     
  527.     if(percent>1.0) percent=1.0;
  528.     if(percent<0.0) percent=0.0;
  529.     
  530.     ipercent=(ULONG)(percent*100+.5);
  531.     
  532.     pos=(WORD)(w*percent+x-1);
  533.     
  534.     if(y1>=y)
  535.     {
  536.       if(x<pos)
  537.       {
  538.         SetAPen(rp,PM->pm_MeterPen);
  539.         RectFill(rp,x,y,pos,y1);
  540.       }
  541.       pos++;  
  542.       if(pos < x+w-1 )
  543.       {
  544.         SetAPen(rp,PM->pm_MeterBgPen);
  545.         RectFill(rp,pos,y,x+w-1,y1);
  546.       }
  547.     }
  548.     if(PM->pm_MeterFormat)
  549.     {
  550.       switch(PM->pm_MeterType)
  551.       {
  552.         case PM_TYPE_PERCENTAGE:
  553.           fb=formatbuffer;
  554.           sprintf(formatbuffer,PM->pm_MeterFormat,ipercent);
  555.           break;
  556.         case PM_TYPE_NUMBER:
  557.           fb=formatbuffer;
  558.           sprintf(formatbuffer,PM->pm_MeterFormat,PM->pm_MeterValue);
  559.           break;
  560.         case PM_TYPE_STRING:
  561.           fb=PM->pm_MeterFormat;
  562.           break;
  563.         default:
  564.           fb=0;
  565.           break;
  566.       }
  567.       if(PM->pm_Screen->BitMap.Depth<2)
  568.         SetDrMd(rp,COMPLEMENT);
  569.  
  570.       MyText(rp,fb, PM->pm_FormatPen,
  571.          PM->pm_MeterCenter,PM->pm_HiLowY);
  572.  
  573.       SetDrMd(rp,JAM1);
  574.     } 
  575.   }
  576. }
  577.  
  578.  
  579. void RefreshPM(ProgressMeter PMeter)
  580. {
  581.   WORD x,w,x1,y;
  582.   LONG l,shine,shadow;
  583.   float tickspace;
  584.   struct RastPort *rp;
  585.   struct _ProgressMeter *PM;
  586.  
  587.   PM=PMeter;
  588.  
  589.   rp=PM->pm_MeterWindow->RPort;
  590.  
  591.   SetDrMd(rp,JAM1);
  592.  
  593.   MyText(rp,PM->pm_LowText, PM->pm_LowTextPen,
  594.          PM->pm_LowCenter,PM->pm_HiLowY);
  595.   MyText(rp,PM->pm_HighText, PM->pm_HighTextPen,
  596.          PM->pm_HighCenter,PM->pm_HiLowY);
  597.   MyText(rp,PM->pm_MeterLabel, PM->pm_MeterLabelPen,
  598.          PM->pm_MeterCenter,PM->pm_LabelY);
  599.   
  600.  
  601.   DrawBevelBox(rp,PM->pm_BarLeftEdge,PM->pm_BarTopEdge,
  602.                   PM->pm_BarWidth,PM->pm_BarHeight,
  603.                     GTBB_Recessed   ,TRUE,
  604.                     GT_VisualInfo   ,PM->pm_VisualInfo,
  605.                     TAG_DONE);
  606.   
  607.   
  608.   x=PM->pm_BarLeftEdge;
  609.   w=PM->pm_BarWidth;
  610.   y=PM->pm_BarTopEdge+PM->pm_BarHeight-1;
  611.   
  612.   shine =PM->pm_DrawInfo->dri_Pens[SHINEPEN];
  613.   shadow=PM->pm_DrawInfo->dri_Pens[SHADOWPEN];  
  614.  
  615.   if(PM->pm_NumTicks)
  616.   {
  617.     tickspace=w/PM->pm_NumTicks;
  618.     for(l=1;l<PM->pm_NumTicks;l++)
  619.     {
  620.       x1=x+l*tickspace+1;
  621.       SetAPen(rp,shadow);
  622.       Move(rp,x1,y);
  623.       Draw(rp,x1,y+4);
  624.       SetAPen(rp,shine);
  625.       Draw(rp,x1+1,y+4);
  626.       Draw(rp,x1+1,y);
  627.     }
  628.   }
  629.   RenderBar(PM);
  630. }
  631.  
  632. void MyText(struct RastPort *RP, STRPTR Str, UBYTE Pen, WORD X, WORD Y)
  633. {
  634.   WORD l,len;
  635.   if(RP && Str)
  636.   {
  637.     len=strlen(Str);
  638.     l=TextLength(RP,Str,len);
  639.     X=X-l/2;
  640.     Move(RP,X,Y);
  641.     SetAPen(RP,Pen);
  642.     Text(RP,Str,len);
  643.   }
  644. }
  645.   
  646. /*
  647.        ng.ng_TopEdge=wintbor +4;
  648.               ng.ng_LeftEdge=winlbor+4;
  649.  
  650.             if(pm->pm_MeterLabel)
  651.             {
  652.               ng.ng_GadgetID=0;
  653.               ng.ng_Width=width-8-winlbor-winlbor;
  654.               pm->pm_GTGads[0]=gad=CreateGadget(TEXT_KIND,gad,&ng,
  655.                           GTTX_Justification,GTJ_CENTER,
  656.                           GTTX_Clipped      ,TRUE,
  657.                           GTTX_Text   ,pm->pm_MeterLabel,
  658.                           GTTX_Border ,FALSE,
  659.                           TAG_DONE);
  660.               ng.ng_TopEdge+=(pm->pm_Font->tf_YSize+6);
  661.             }
  662.  
  663.             pm->pm_BarTopEdge=ng.ng_TopEdge;
  664.             pm->pm_BarHeight =pm->pm_Font->tf_YSize+4;
  665.  
  666.             ng.ng_Width=hilowlen;
  667.           
  668.             ng.ng_GadgetID=1;
  669.             ng.ng_LeftEdge=winlbor+4;
  670.             pm->pm_GTGads[1]=gad=CreateGadget(TEXT_KIND,gad,&ng,
  671.                             GTTX_Justification,GTJ_CENTER,
  672.                             GTTX_Clipped      ,TRUE,
  673.                             GTTX_Text   ,pm->pm_LowText,
  674.                             GTTX_Border ,FALSE,
  675.                             TAG_DONE);
  676.             pm->pm_BarLeftEdge=ng.ng_LeftEdge+hilowlen+2;
  677.             
  678.             ng.ng_GadgetID=2;
  679.             ng.ng_LeftEdge=width-winrbor-4-hilowlen;
  680.             
  681.             pm->pm_GTGads[1]=gad=CreateGadget(TEXT_KIND,gad,&ng,
  682.                             GTTX_Justification,GTJ_CENTER,
  683.                             GTTX_Clipped      ,TRUE,
  684.                             GTTX_Text   ,pm->pm_HighText,
  685.                             GTTX_Border ,FALSE,
  686.                             TAG_DONE);
  687.  
  688.             pm->pm_BarWidth   =ng.ng_LeftEdge-pm->pm_BarLeftEdge-2;
  689. */
  690.  
  691.